package servlet;

import bean.Hero;
import dao.HeroDAO;
import net.sf.json.JSONSerializer;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class GetManyServlet extends HttpServlet {

    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        List<Hero> heros = new HeroDAO().list();

        String result = JSONSerializer.toJSON(heros).toString();

        response.setContentType("text/html;charset=utf-8");
        response.getWriter().print(result);
    }
}